package com.zm.rpc.server.dispatcher.handler;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.zm.rpc.procedure.ProcedureCenter;
import com.zm.rpc.procedure.pojo.ProcedureCallResult;
import com.zm.rpc.protocol.request.RpcRequest;


@Component
public class RPCRequestHandler implements IDispatcherHandler<RpcRequest>{
    private static final Logger log = Logger.getLogger(RPCRequestHandler.class);


    @Autowired
    private ProcedureCenter procduerCenter;

    @Override
    public Object doExecute(RpcRequest req) {
        log.debug(String.format("RPC Request Received:%s", req.toString()));
        ProcedureCallResult result = procduerCenter.call(req.getProcedurePath(), req.getParams());
        return result.getResult();
    }
    
}
